import defaultSettings from '@/settings'
import addNsname from '../add-nsname'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings
const name = 'settings' // 模块名
const nsname = name + '/' // 命名空间模块名

const state = {
  showSettings: showSettings,
  fixedHeader: fixedHeader,
  sidebarLogo: sidebarLogo
}

const mutations = {
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}
addNsname(nsname, mutations)

const actions = {
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}
addNsname(nsname, actions)

export default {
  name,
  namespaced: true,
  state,
  mutations,
  actions
}

